package com.qifan.alb2b.service.route;

import javax.swing.event.CaretEvent;

import org.springframework.stereotype.Component;
import org.springframework.web.context.support.WebApplicationObjectSupport;

import com.qifan.alb2b.action.front.param.PersonNum;
import com.qifan.alb2b.domain.RouteInfoDomain;
import com.qifan.alb2b.service.vo.RouteVo;
import com.qifan.alb2b.service.vo.StPriceTable;
import com.qifan.alb2b.util.Constants;

/**
 * 算法的上下文简单工厂
 * @author hc24
 *
 */
@Component
public class StPriceContext extends WebApplicationObjectSupport{
	private IStPrice stPrice;
	
	public StPriceContext(){}	
	
	/**
	 * 根据团体类型得到具体的算法类
	 * @param type
	 */
	private void create(int type) {
		switch(type){
			case Constants.GROUP_TYPE_SIX:
				stPrice=(IStPrice) getWebApplicationContext().getBean("sixStPrice");
				break;
			case Constants.GROUP_TYPE_SEVEN:
				stPrice=(IStPrice) getWebApplicationContext().getBean("sevenStPrice");
				break;
		}
	}
	
	/**
	 * 得到最低价格
	 * @param route
	 * @param type
	 * @return
	 */
	public double getLowest(RouteInfoDomain route,int type){
		create(type);
		return stPrice.calcLowest(route);
	}
	
	/**
	 * 得到标准配套价格
	 * @param route
	 * @param type
	 * @return
	 */
	public StPriceTable getStPriceTable(RouteInfoDomain route,int type){
		create(type);
		return stPrice.calcStTable(route);
	}
	
	/**
	 * 初始化标配资源
	 * @param routeVo
	 * @param type
	 */
	public void initStRes(RouteVo routeVo,int type){
		create(type);
		stPrice.initStRes(routeVo);
	}
	
	public double[] calcTotalPrice(PersonNum personNum,StPriceTable spt,int type){
		create(type);
		return stPrice.calcTotalPrice(personNum, spt);
	}
}
